package com.finger.forest.adapter;
import android.content.Context;
import android.content.Intent;
import android.view.*;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.finger.forest.HotCheckActivity;
import com.finger.forest.HotListActivity;
import com.finger.forest.R;
import com.finger.forest.model.FzHotspot;
import com.finger.forest.utils.ToastUtils;

import java.util.List;
import java.util.Map;


public class MyAdapter extends BaseAdapter{
    private Context context;
    private List<FzHotspot> mList;//数据源
    private LayoutInflater mInflater;//布局装载器对象
    private int type = 0;//反馈标识 0：未反馈；1：已反馈。

    // 通过构造方法将数据源与数据适配器关联起来
    // context:要使用当前的Adapter的界面对象
    public MyAdapter(Context context, List<FzHotspot> list, int type) {
        this.context = context;
        this.mList = list;
        this.type = type;
        this.mInflater = LayoutInflater.from(context);
    }

    @Override
    //ListView需要显示的数据数量
    public int getCount() {
        return mList.size();
    }

    @Override
    //指定的索引对应的数据项
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    //指定的索引对应的数据项ID
    public long getItemId(int position) {
        return position;
    }

    @Override
    //返回每一项的显示内容
    public View getView(int position, View convertView, ViewGroup parent) {
        //将布局文件转化为View对象
        View view = mInflater.inflate(R.layout.item_hot,null);

        /**
         * 找到item布局文件中对应的控件
         */
        TextView hotName = (TextView) view.findViewById(R.id.tv_hot_name);
        TextView hotCodeName = (TextView) view.findViewById(R.id.tv_hot_code);
        TextView hotAddressName = (TextView) view.findViewById(R.id.tv_hot_address);
        Button detailBtn = (Button) view.findViewById(R.id.detailBtn);

        //获取相应索引的ItemBean对象
        FzHotspot bean = mList.get(position);

        /**
         * 设置控件的对应属性值
         */
        hotName.setText(bean.gethCondition());
        hotCodeName.setText(bean.gethHotspotNo());
        hotAddressName.setText(bean.gethHotspotLoc());
        detailBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intentHotCheck = new Intent(context, HotCheckActivity.class);
                intentHotCheck.putExtra("hId", bean.gethId());//热点ID
                intentHotCheck.putExtra("type", type);//反馈类型
                context.startActivity(intentHotCheck);
            }
        });

        return view;
    }
}